// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

  @property([cc.SpriteAtlas])
  atlas: cc.SpriteAtlas = null
  frams: cc.SpriteFrame[] = []
  sprite: cc.Sprite = null
  index: number = 0
  onLoad () {
    this.sprite = this.node.getComponent(cc.Sprite)
    // 从图集中获取所有帧的图片
    if (this.atlas)
    this.frams = this.atlas.getSpriteFrames()
    this.sprite.spriteFrame = this.frams[this.index]
    this.node.on('touchstart', this.onTouchstart, this)
  }

  onTouchstart () {
    cc.resources.load('icon/汽车', cc.SpriteFrame, (err, assets) => {
      this.node.getComponent(cc.Sprite).spriteFrame = <cc.SpriteFrame> assets
    })
  }

  start () {

  }

  update (dt) {
    // if (this.index === 11) {
    //   this.index = 0
    // }
    // this.sprite.spriteFrame = this.frams[this.index]
    // this.index ++
  }
}
